PyIgnition

https://github.com/animatinator/PyIgnition update for Python 3
Clone: git clone https://git.frombelow.net/PyIgnition.git
Log | Files | Refs | README

Line counter.py (2243B)


      1 import os
      2 
      3 lines = 0
      4 linesextended = 0
      5 comments = 0
      6 whitespace = 0
      7 files = os.listdir(os.getcwd())
      8 allowedextensions = ["py"]
      9 excluded = ["Bubbles!.py", "Catherine wheel.py", "Controlled Eruption.py", "Gravity test.py",
     10 	    "Keyframe selector widget testery.py", "keyframes test.py", "particleeditor.py",
     11 	    "pygamedisplay.py", "PyIgnition test - fire.py", "Test load.py", "timelinectrl.py",
     12 	    "Vortex gravity test.py", "Water.py", "Wind.py", "wx test.py", "wx test 2.py",
     13 	    "xml OLD.py", "XML reader test.py"]
     14 
     15 print ("     --ExeSoft line counter--")
     16 print
     17 print ("Counting lines in all files with the following extensions:")
     18 
     19 for extension in allowedextensions:
     20     print ("\t*.%s" % extension)
     21 
     22 print
     23 print ("Excluding the following files:")
     24 
     25 for excludedfile in excluded:
     26 	print ("\t%s" % excludedfile)
     27 print
     28 print ("Counting...")
     29 
     30 for item in files:
     31 	extension = item.split(".")[len(item.split(".")) - 1]
     32 	if (extension in allowedextensions) and (item not in excluded) and (item != "Line counter.py"):
     33 		opened = open(item)
     34 		print ("\tCounting in \'%s\'..." % item)
     35 		
     36 		totalcount = 0
     37 		totalextended = 0
     38 		for line in opened.readlines():
     39 			temp = line.replace("\t", "")
     40 			temp = temp.replace(" ", "")
     41 			temp = temp.replace("\n", "")
     42 			if (temp != "") and (temp[0] != "#"):
     43 				totalcount += 1
     44 				totalextended += 1
     45 			else:
     46 				if temp == "":
     47 				    whitespace += 1
     48 				elif temp[0] == "#":
     49 				    comments += 1
     50 				totalextended += 1
     51 		
     52 		lines += totalcount
     53 		linesextended += totalextended
     54 		opened.close()
     55 
     56 print
     57 print ("Done!")
     58 input()
     59 print
     60 print
     61 print ("Line counts:\n\t-Excluding comments and whitespace: %i\n\t-Everything: %i" % (lines, linesextended))
     62 input()
     63 print
     64 print ("Extras:\n\t-Number of comments: %i\n\t-Number of blank lines: %i" % (comments, whitespace))
     65 input()
     66 print
     67 codepercent = (float(lines) / float(linesextended)) * 100.0
     68 commentpercent = (float(comments) / float(linesextended)) * 100.0
     69 whitespacepercent = (float(whitespace) / float(linesextended)) * 100.0
     70 print ("Code breakdown:")
     71 print ("\t-Functional code: %f%%\n\t-Comments: %f%%\n\t-Whitespace: %f%%" % (codepercent, commentpercent, whitespacepercent))
     72 input()